/*
 * Created on 13-jun-2005
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.mushroomdb.engine.optimizer;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.mushroomdb.engine.operation.RelationOperation;


/**
 * @author Admin
 * Optimizador que ejecuta secuencialmente otros optimizadores.
 */
public class CompositeOptimizer implements Optimizer {

	private List<Optimizer> optimizerPool;
	
	/**
	 * Construye un optimizador basado en un pool de optimizadores.
	 *
	 */
	public CompositeOptimizer() {
		this.optimizerPool = new LinkedList<Optimizer>();
		
		/*this.optimizerPool.add(new SelectionExplodingOptimizer());
		this.optimizerPool.add(new ProjectionPushingOptimizer());
		this.optimizerPool.add(new SelectionPushingOptimizer());
		this.optimizerPool.add(new AccessMethodDefiningOptimizer());*/
		
		//this.optimizerPool.add(new JoinSwitchingOptimizer());
		//this.optimizerPool.add(new JoinMethodDefiningOptimizer());
	}
	
	/**
	 * Adds an optimizer to the composition.
	 * @param optimizer
	 */
	public void addOptimizer(Optimizer optimizer) {
		this.optimizerPool.add(optimizer);
	}
	
	/**
	 * @see org.mushroomdb.engine.optimizer.Optimizer#optimize(com.mdlm.rdbms.engine.operation.RelationOperation)
	 */
	public RelationOperation optimize(RelationOperation relationOperation) {
		Iterator<Optimizer> iterator = this.optimizerPool.iterator();
		RelationOperation optimizedRelationOperation = relationOperation;
		while (iterator.hasNext()) {
			Optimizer optimizer = iterator.next();
			optimizedRelationOperation = optimizer.optimize(optimizedRelationOperation);
		}
		return optimizedRelationOperation;
	}

}
